package com.example.villagemarket;

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;

import android.util.Log;

public class HTTPPost {

	HttpClient httpclient;
	HttpPost httppost; 
	List<NameValuePair> params;
	HttpResponse response = null;
	HttpEntity entity;
	InputStream instream;
	
	ResponseHandler<String> responseHandler;
    String responseString =""; 
    



	public HTTPPost(String[] parameters, String url) {
		
		responseHandler = new BasicResponseHandler();
		httpclient = new DefaultHttpClient();
		
		httppost = new HttpPost(url);

		

		try {
			if(parameters != null)
			{
				params = new ArrayList<NameValuePair>(parameters.length);
				for (int i = 0; i < parameters.length; i++) {
					params.add(new BasicNameValuePair("param-" + i, parameters[i]));
				}
				httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
			}
			
			responseString = httpclient.execute(httppost,responseHandler);
		} catch (UnsupportedEncodingException e3) {
			// TODO Auto-generated catch block
			e3.printStackTrace();
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
				
	}
}
